package com.hz.ruoyifarmbase.basedata.controller;

import com.hz.ruoyifarmbase.basedata.domain.AgrGermType;
import com.hz.ruoyifarmbase.basedata.service.IAgrGermTypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 种质类型Controller
 *
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/genetic")
public class AgrGermTypeController extends BaseController
{
    @Autowired
    private IAgrGermTypeService agrGermTypeService;

    /**
     * 查询种质类型列表
     */
    @RequiresPermissions("basedata:genetic:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrGermType agrGermType)
    {
        startPage();
        List<AgrGermType> list = agrGermTypeService.selectAgrGermTypeListInner(agrGermType);
        return getDataTable(list);
    }



    /**
     * 导出种质类型列表
     */
    @RequiresPermissions("basedata:genetic:export")
    @Log(title = "种质类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgrGermType agrGermType)
    {
        System.out.println("导出种质类型列表");
        List<AgrGermType> list = agrGermTypeService.selectAgrGermTypeList(agrGermType);
        ExcelUtil<AgrGermType> util = new ExcelUtil<AgrGermType>(AgrGermType.class);
        util.exportExcel(response, list, "种质类型数据");
    }

    /**
     * 获取种质类型详细信息
     */
    @RequiresPermissions("basedata:genetic:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(agrGermTypeService.selectAgrGermTypeByTypeId(typeId));
    }

    /**
     * 新增种质类型
     */
    @RequiresPermissions("basedata:genetic:add")
    @Log(title = "种质类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgrGermType agrGermType)
    {
        return toAjax(agrGermTypeService.insertAgrGermType(agrGermType));
    }

    /**
     * 修改种质类型
     */
    @RequiresPermissions("basedata:genetic:edit")
    @Log(title = "种质类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgrGermType agrGermType)
    {
        return toAjax(agrGermTypeService.updateAgrGermType(agrGermType));
    }

    /**
     * 删除种质类型
     */
    @RequiresPermissions("basedata:genetic:remove")
    @Log(title = "种质类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(agrGermTypeService.deleteAgrGermTypeByTypeIds(typeIds));
    }

    /**
     * 获取种质类型树列表
     */
    @RequiresPermissions("basedata:genetic:list")
    @GetMapping("/agrGermTypeTree")
    public AjaxResult agrGermTypeTree(AgrGermType agrGermType)
    {
        return success(agrGermTypeService.selectAgrGermTypeTreeList(agrGermType));
    }
}
